import { FormSchema } from '/@/components/Table';

export const searchFormSchema: FormSchema[] = [
  {
    label: '数据源类型',
    field: 'source',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: 'Kafka', value: 'KAFKA' },
        { label: 'RocketMQ', value: 'RocketMQ' },
        { label: 'RabbitMQ', value: 'RabbitMQ' },
      ],
    },
  },
  {
    label: 'ID',
    field: 'id',
    colProps: { span: 6 },
    component: 'Input',
  },
];
const isKafka = (type) => type === 'KAFKA';
const isRocketMQ = (type) => type === 'ROCKET_MQ';
const isPulsar = (type) => type === 'PULSAR';
const isMysql = (type) => type === 'MYSQL' || type == 'SQLSERVER' || type == 'TDENGINE' || type == 'CLICKHOUSE';
const isMongodb = (type) => type === 'MONGODB';
const isWebHook = (type) => type === 'WEBHOOK';
const isLog = (type) => type === 'LOG';
const isRabbitMQ = (type) => type === 'RABBIT_MQ';
const isClinetId = (type) => type === 'MQTT';
const isNotAdd = (type) => type !== 'LOG';
const isHost = (type) => type === 'RABBIT_MQ' || type === 'REDIS' || type === 'MQTT';
const isDefault = (type) => type !== 'KAFKA' && type !== 'ROCKET_MQ' && type !== 'PULSAR' && type !== 'WEBHOOK' && type !== 'REDIS' && type !== 'LOG';
export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'source',
    label: '数据源类型',
    component: 'Input',
    show: false,
  },
  {
    field: 'sourceName',
    label: '数据源名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'url',
    label: '请求地址',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isWebHook(values.source),
  },
  {
    field: 'method',
    label: '请求方法',
    component: 'Input',
    slot: 'reqMethod',
    ifShow: ({ values }) => isWebHook(values.source),
  },
  {
    field: 'sourceAttributes',
    label: '',
    component: 'Input',
    slot: 'add',
    ifShow: ({ values }) => isNotAdd(values.source),
  },
  {
    field: 'bootstrap.servers',
    label: 'bootstrap.servers',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isKafka(values.source),
  },
  {
    field: 'key.serializer',
    label: 'key.serializer',
    component: 'Input',
    required: true,
    defaultValue: 'org.apache.kafka.common.serialization.StringSerializer',
    ifShow: ({ values }) => isKafka(values.source),
  },
  {
    field: 'value.serializer',
    label: 'value.serializer',
    component: 'Input',
    required: true,
    defaultValue: 'org.apache.kafka.common.serialization.StringSerializer',
    ifShow: ({ values }) => isKafka(values.source),
  },
  {
    field: 'nameServerAddr',
    label: 'nameServerAddr',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isRocketMQ(values.source),
  },
  {
    field: 'producerGroup',
    label: 'producerGroup',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isRocketMQ(values.source),
  },
  {
    field: 'instanceName',
    label: 'instanceName',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isRocketMQ(values.source),
  },
  {
    field: 'serviceUrl',
    label: 'serviceUrl',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isPulsar(values.source),
  },
  {
    field: 'jdbcUrl',
    label: 'jdbcUrl',
    component: 'Input',
    required: true,
    defaultValue: '',
    ifShow: ({ values }) => isMysql(values.source),
  },
  {
    field: 'url',
    label: 'url',
    component: 'Input',
    required: true,
    defaultValue: 'mongodb://127.0.0.1:27017',
    ifShow: ({ values }) => isMongodb(values.source),
  },
  {
    field: 'clientId',
    label: 'clientId',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isClinetId(values.source),
  },
  {
    field: 'host',
    label: 'host',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isHost(values.source),
  },
  {
    field: 'port',
    label: 'port',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isHost(values.source),
  },
  {
    field: 'vhost',
    label: 'vhost',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isRabbitMQ(values.source),
  },
  {
    field: 'username',
    label: 'userName',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isDefault(values.source),
  },
  {
    field: 'password',
    label: 'passWord',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isDefault(values.source),
  },
  {
    field: 'database',
    label: 'database',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isMongodb(values.source),
  },
  {
    field: 'log',
    label: '日志名称',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => isLog(values.source),
  },
];
export const formSchema1: FormSchema[] = [
  {
    label: '',
    field: 'params',
    component: 'Select',
    componentProps: {
      placeholder: '请输入属性名',
      getPopupContainer: (node) => document.body,
      options: [
        { label: 'acks', value: 'acks' },
        { label: 'compression.type', value: 'compression.type' },
        { label: 'batch.size', value: 'batch.size' },
        { label: 'client.id', value: 'client.id' },
        { label: 'client.rack', value: 'client.rack' },
        { label: 'client.dns.lookup', value: 'client.dns.lookup' },
        { label: 'group.id', value: 'group.id' },
        { label: 'group.instance.id', value: 'group.instance.id' },
        { label: 'linger.ms', value: 'linger.ms' },
        { label: 'max.poll.interval.ms', value: 'max.poll.interval.ms' },
        { label: 'rebalance.timeout.ms', value: 'rebalance.timeout.ms' },
        { label: 'session.timeout.ms', value: 'session.timeout.ms' },
        { label: 'heartbeat.interval.ms', value: 'heartbeat.interval.ms' },
        { label: 'default.api.timeout.ms', value: 'default.api.timeout.ms' },
        { label: 'request.timeout.ms', value: 'request.timeout.ms' },
        { label: 'reconnect.backoff.ms', value: 'reconnect.backoff.ms' },
        { label: 'reconnect.backoff.max.ms', value: 'reconnect.backoff.max.ms' },
        { label: 'retries', value: 'retries' },
        { label: 'retry.backoff.ms', value: 'retry.backoff.ms' },
        { label: 'security.protocol', value: 'security.protocol' },
        { label: 'metadata.max.age.ms', value: 'metadata.max.age.ms' },
        { label: 'send.buffer.bytes', value: 'send.buffer.bytes' },
        { label: 'receive.buffer.bytes', value: 'receive.buffer.bytes' },
      ],
    },
  },
];
export const formSchema2: FormSchema[] = [
  {
    label: '',
    field: 'params',
    component: 'Input',
    componentProps: {
      placeholder: '请输入请求方法',
    },
  },
];
export interface Source {
  img?: string;
  name?: string;
  desc?: string;
  bkground?: string;
}
export const sources: Source[] = [
  {
    img: '',
    name: 'KAFKA',
    desc: 'Kafka',
    bkground: 'rgba(243, 244, 246, 0.5)',
  },
  {
    img: '',
    name: 'ROCKET_MQ',
    desc: 'RocketMQ',
    bkground: 'rgb(254, 250, 223)',
  },
  {
    img: '',
    name: 'RABBIT_MQ',
    desc: 'RabbitMQ',
    bkground: 'rgb(254, 249, 219)',
  },
  {
    img: '',
    name: 'PULSAR',
    desc: 'Pulsar',
    bkground: 'rgba(38, 134, 255, 0.19)',
  },
  {
    img: '',
    name: 'MYSQL',
    desc: 'Mysql',
    bkground: 'rgb(229, 250, 252)',
  },
  {
    img: '',
    name: 'MONGODB',
    desc: 'Mongodb',
    bkground: 'rgb(229, 250, 252)',
  },
  {
    img: '',
    name: 'SQLSERVER',
    desc: 'Sqlserver',
    bkground: 'rgb(187, 217, 255)',
  },
  {
    img: '',
    name: 'POSTGRESQL',
    desc: 'Postgresql',
    bkground: 'rgb(220, 234, 253)',
  },
  {
    img: '',
    name: 'ORACLE',
    desc: 'Oracle',
    bkground: 'rgb(255, 241, 246)',
  },
  {
    img: '',
    name: 'TDENGINE',
    desc: 'Tdengine',
    bkground: 'rgb(220, 234, 253)',
  },
  {
    img: '',
    name: 'CLICKHOUSE',
    desc: 'Clickhouse',
    bkground: 'rgb(254, 250, 223)',
  },
  {
    img: '',
    name: 'WEBHOOK',
    desc: 'Webhook',
    bkground: 'rgb(232, 250, 252)',
  },
  {
    img: '',
    name: 'MQTT',
    desc: 'MQTT',
    bkground: 'rgb(255, 241, 246)',
  },
  {
    img: '',
    name: 'REDIS',
    desc: 'Redis',
    bkground: 'rgb(255, 240, 245)',
  },
  {
    img: '',
    name: 'LOG',
    desc: 'Log',
    bkground: 'rgb(243, 244, 246)',
  },
];
